package com.example.controller;

import com.example.beans.Book;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * Author:sun
 * Date:2021/12/20
 * Note:*
 **/

@Controller
@RequestMapping("/book")
public class BookController {

    @RequestMapping("/query")
    public String queryBook(int bookId, Model model) {
        Book book = new Book(bookId, "java", "LianGe",2.22);

        List<Book> books = new ArrayList<>();
        books.add(new Book(1,"java","LianGe1",2.2));
        books.add(new Book(2,"html","LianGe2",40));
        books.add(new Book(3,"c++","LianGe3",41));
        books.add(new Book(4,"python","LianGe4",56));

        //简单类型
        model.addAttribute("price",0.32);
        //字符串
        model.addAttribute("str","Long long ago");
        model.addAttribute("color","orange");
        //对象
        model.addAttribute("book", book);
        //集合
        model.addAttribute("books",books);

        //这里的text指src/main/resources/templates/test.html
        return "test";
    }

    @RequestMapping("/delete")
    //测试网址：http://localhost:8080/book/delete?bookId=1
    public String deleteBook(int bookId){
        System.out.println("------delete");
        return "a";
    }
}
